﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeManageService
{
    static class Program
    {
		static void Main()
        {
			PlanDBManager db = new PlanDBManager();
			UserDBManager udb = new UserDBManager();

			if ((from user in udb.GetAllUsers() where user.UserName == "2333" select user).Count() == 0)
				udb.addUser(new User("2333", "2333"));

			PlanManager.Initialrize("2333");

			Notifier notifier = new Notifier();
            notifier.StartNotice += Program.TestNotifier;
            notifier.StartTimer("yyz");

            Console.WriteLine("ready!");
            Console.WriteLine("按任意键停止计时");
            Console.ReadKey();
            notifier.StopTimer();
			
            FileManager.SetDefault();
            FileManager.Write();
            Console.WriteLine(FileManager.Read());
			
			Console.WriteLine("按任意键退出...");
			Console.ReadKey();
			return;
        }

        static public void TestNotifier(NoticeArgs args)
        {
            if (args.Plans.Count == 0) ;
            else if (args.State == 0)
            {
                Console.WriteLine("以下是即将开始的任务ID");
                foreach (Plan plan in args.Plans)
                {
                    Console.WriteLine(plan.PlanID);
                }
            }
            else
            {
                Console.WriteLine("以下是即将到期的任务ID");
                foreach (Plan plan in args.Plans)
                {
                    Console.WriteLine(plan.PlanID);
                }
            }
        }
    }
}
